package yunquan.wang.base.process;

import java.util.Map;

import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.wsht.HornetQHTWorkItemHandler;
import org.jbpm.task.TaskService;
import org.jbpm.task.service.SyncTaskServiceWrapper;
import org.jbpm.task.service.hornetq.AsyncHornetQTaskClient;
import org.springframework.beans.factory.InitializingBean;

public class ProcessServiceHornetQ implements ProcessService,InitializingBean {
 
	private StatefulKnowledgeSession ksession;
	private   TaskService taskClient;
	@Override
	public TaskService getTaskService() {
        
		return taskClient;
	}
	public void setKsession(StatefulKnowledgeSession ksession) {
		this.ksession=ksession;
	}
	@Override
	public void afterPropertiesSet() throws Exception {
		 taskClient = new SyncTaskServiceWrapper(new AsyncHornetQTaskClient());
		 
		 //Register WorkItem Mina 
	    HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession);
        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler);
	}
	@Override
	public void startProcess(String string, Map<String, Object> params) {
		ksession.startProcess(string, params);
	}

}
